package reflect;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class ReflectDemo2 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        ArrayList list = new ArrayList();
        System.out.println(list);

        //1.获取要实例化对象的类的类对象
//        Class cls = Class.forName("java.util.ArrayList");
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入类名:");
        String className = scan.nextLine();
        Class cls = Class.forName(className);
        //2.调用Class的newInstance()来调用无参构造器
        Object obj = cls.newInstance();
        System.out.println(obj);
    }
}
